package com.pignest.hotel.beans;

import com.pignest.hotel.annotation.Bean;
import com.pignest.hotel.beans.global.BaseBean;

/**
 * 角色权限表
 * Access Control List
 * */
@Bean("角色权限")
public class ACL extends BaseBean {

	private static final long serialVersionUID = -2147614816917307058L;
	
	private Role role;
	private String permission;
	
	public ACL() {
	}
	
	public ACL(Role role, String permission) {
		this.role = role;
		this.permission = permission;
	}
	
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	public String getPermission() {
		return permission;
	}
	public void setPermission(String permission) {
		this.permission = permission;
	}
	
	@Override
	public int hashCode() {
		if (role != null && permission != null)
			return role.hashCode() + permission.hashCode();
		return super.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ACL))
			return false;
		ACL t = (ACL)obj;
		if (id != null && id.equals(t.id))
			return true;
		if (role == null || permission == null || t.role == null || t.permission == null)
			return false;
		return role.getId().equals(t.role.getId()) && permission.equals(t.permission);
	}
	
	@Override
	public String toSimpleString() {
		return permission + "/" + role.getName();
	}
}
